Names, Homework

Below is three lines of python code, the only thing you have seen yet is the "*" symbol which means multiplication. Your task comes in three parts:

  1. Figure out what the code is supposed to do. (this might take some googling hint: think circles!)
  2. Add a comment or two, explaining what it does.
  3. Change the name "belt_size" and "cake" to something more meaningful.

In [1]:
cake = 3.14
diameter = 2

belt_size = cake * diameter

Example Solution


In [2]:
# calculate the circumference of a circle
pi = 3.14
diameter = 2

circumference = pi * diameter

Even Better Solution


In [ ]:
PI = 3.14
diameter = 2

circumference = PI * diameter

So this solution is a bit better because pi is a mathmatical constant, and so therefore should probably be made into a constant. Which means the name should be in all-caps. I also removed the comment because I think what the code does is clearr from the context.


In [ ]: